package com.swind.fast.modules.app.mock;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.swing.filechooser.FileSystemView;

import org.apache.commons.io.IOUtils;
import com.swind.fast.common.api.vo.Result;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import lombok.extern.slf4j.Slf4j;

@RestController
@RequestMapping("/app/mock/api")
@Slf4j
public class MockController {
    private final String JSON_PATH = "classpath:com/swind/fast/modules/app/demo/mock/json/";

    /**
      * 测试报表数据
     */
    @GetMapping(value = "/report/getYearCountInfo")
    public String getYearCountInfo() {
        return readJson(JSON_PATH + "getCntrNoCountInfo.json");
    }
    @GetMapping(value = "/report/getMonthCountInfo")
    public String getMonthCountInfo() {
        return readJson(JSON_PATH + "getCntrNoCountInfo.json");
    }
    @GetMapping(value = "/report/getCntrNoCountInfo")
    public String getCntrNoCountInfo() {
        return readJson(JSON_PATH + "getCntrNoCountInfo.json");
    }
    @GetMapping(value = "/report/getCabinetCountInfo")
    public String getCabinetCountInfo() {
        return readJson(JSON_PATH + "getCntrNoCountInfo.json");
    }

    /**
     * 读取json格式文件
     * @param jsonSrc
     * @return
     */
    private String readJson(String jsonSrc) {
        String json = "";
        try {
            //File jsonFile = ResourceUtils.getFile(jsonSrc);
            //json = FileUtils.re.readFileToString(jsonFile);
            //换个写法，解决springboot读取jar包中文件的问题
            InputStream stream = getClass().getClassLoader().getResourceAsStream(jsonSrc.replace("classpath:", ""));
            json = IOUtils.toString(stream,"UTF-8");
        } catch (IOException e) {
            log.error(e.getMessage(),e);
        }
        return json;
    }
}